<template>
  <div>
    <van-nav-bar
      title="新增地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-edit
      :area-list="areaList"
      show-search-result
      @save="onSave"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import areaList from "../api/area.js";
import { Toast } from "vant";
import axios from "axios";

export default {
  name: "Address",
  data() {
    return {
      info: [],
      areaList,
      searchResult: [],
      form: {
        name: '',
        tel: '',
        area: '',
        detail: '',
      },
    };
  },
  created() {
    
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSave(content) {
      axios
        .post("/api/addressadd.php", {
          name: content.name,
          tel: content.tel,
          detail: content.province + content.city + content.county + content.addressDetail,
          users: localStorage.getItem('username'),
        })
        .then((response) => {
          console.log(response);
          Toast.success("添加成功");
          history.go(-1);
        });
        window.console.log('确认')
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区',
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  }
  
};
</script>

<style>
</style>